<template>
    <div class="box" style="padding: 20px;">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="名称" prop="name" class>
                <el-input v-model="ruleForm.name"></el-input>
            </el-form-item>
            <el-form-item label="说明" prop="profile">
                <el-input type="textarea" :rows="2" v-model="ruleForm.profile">
                </el-input>
            </el-form-item>

            <el-form-item label="权限" style="height: 400px; width: 100%; overflow: auto;">
                <label v-for="r in rolepowerlist" :key="r.id">
                    <input type="checkbox" v-model="r.falg">{{ r.name }}
                </label>
            </el-form-item>

            <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        </el-form>
    </div>
</template>
<script>
import { power, poweradd, editorle } from "@/api/roleManage";
export default {
    data() {
        return {
            ruleForm: {
                name: '',
                profile: "",
                actionsIds: ''
            },
            rolepowerlist: [],
            rules: {
                name: [
                    { required: true, message: '不能为空', trigger: 'blur' },
                ],
                profile: [
                    { required: true, message: '不能为空', trigger: 'blur' }
                ]
            }
        };
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    console.log(this.ruleForm);
                    this.poweradd(this.ruleForm)

                    this.$message({
                        message: '添加成功',
                        type: 'success',
                        duration: "2000"
                    });
                    setTimeout(() => {
                        this.$router.push('/RoleManage')
                    }, 2000);
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        async getpoeer() {
            let { data: res } = await power()
            console.log(res);
            this.rolepowerlist = res
            this.geteditorle()

        },
        async poweradd() {
            let { data: res } = await poweradd(this.ruleForm)
            this.ruleForm = res

        },
        async geteditorle() {
            let { data: res } = await editorle({ id: this.$route.params.row })
            console.log(res);
        }

    },
    mounted() {
        this.getpoeer()
    }
}

</script>
<style lang="scss" scoped>

::-webkit-scrollbar {
    overflow: hidden;
}

.el-input__inner {
    /* background-color: aqua; */
    width: 1100px;
    margin-top: 10px;
}

.el-textarea__inner {
    width: 1100px;
}

.el-form-item__content {
    width: 1100px;

}

.el-form-item__content {
    color: #000;
    margin-left: 10px;
    margin-right: 10px;
}

.el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
}

.el-icon-arrow-down {
    font-size: 12px;
}

.demonstration {
    display: block;
    color: #8492a6;
    font-size: 14px;
    margin-bottom: 20px;
}
</style>
